package com.alarmtoexercise.alarm;

import com.alarmtoexercise.util.Tools;

import android.content.Context;
import android.content.Intent;
import android.content.BroadcastReceiver;
import android.util.Log;

public class AlarmInitReceiver extends BroadcastReceiver {
	
	private final static String LOG_CLASS = "AlarmInitReceiver";

    /**
     * Sets alarm on ACTION_BOOT_COMPLETED.  Resets alarm on
     * TIME_SET, TIMEZONE_CHANGED
     */
    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (Tools.DEBUG)
        	Log.v(LOG_CLASS, "AlarmInitReceiver" + action);

        if (context.getContentResolver() == null) {
            Log.e(LOG_CLASS, "AlarmInitReceiver: FAILURE unable to get content resolver.  Alarms inactive.");
            return;
        }
        if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
            AlarmProcessor.saveSnoozeAlert(context, -1, -1);
            AlarmProcessor.disableExpiredAlarms(context);
        }
        AlarmProcessor.setNextAlert(context);
    }
}
